<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: 'doctor-info'
});

import { useCrud, useTable, useUpsert, useSearch } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useI18n } from 'vue-i18n';
import { reactive } from 'vue';
import { useDict } from '/$/dict';

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	gender: [
		{ label: t('男'), value: 0 },
		{ label: t('女'), value: 1 },
		{ label: t('未知'), value: 2 }
	],
	department: [{ label: t('双博视'), value: 0 }],
	title: [{ label: t('验光师'), value: 0 }]
});
const { dict } = useDict();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t('姓名'),
			prop: 'name',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12,
			required: true
		},
		// { label: t('头像'), prop: 'avatar', component: { name: 'cl-upload' } },
		{
			label: t('所属门店'),
			prop: 'shop',
			component: {
				name: 'el-select',
				options: dict.get('Shop')
			},
			span: 12,
			required: true,
			default: ''
		},
		{
			label: t('性别'),
			prop: 'gender',
			component: { name: 'el-radio-group', options: options.gender },
			value: 0,
			required: true,
			span: 8
		},
		{
			label: t('科室'),
			prop: 'department',
			component: {
				name: 'cl-select',
				props: { options: options.department }
			},
			value: 0,
			span: 8,
			required: true
		},
		{
			label: t('职称'),
			prop: 'title',
			component: {
				name: 'el-radio-group',
				props: { clearable: true },
				options: options.title
			},
			value: 0,
			span: 8,
			required: true
		},
		{
			label: t('简介'),
			prop: 'introduction',
			component: {
				name: 'el-input',
				props: { type: 'textarea', rows: 4 }
			}
		}
		// {
		// 	label: t('接诊时间'),
		// 	prop: 'receptionTime',
		// 	component: {
		// 		name: 'el-date-picker',
		// 		props: { type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
		// 	},
		// 	span: 12
		// },
		// {
		// 	label: t('挂号费'),
		// 	prop: 'registrationFee',
		// 	hook: 'number',
		// 	component: { name: 'el-input-number', props: { min: 0 } },
		// 	span: 12,
		// 	required: true
		// }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: 'selection' },
		{ label: t('姓名'), prop: 'name', minWidth: 140 },
		// {
		// 	label: t('头像'),
		// 	prop: 'avatar',
		// 	minWidth: 100,
		// 	component: { name: 'cl-image', props: { size: 60 } }
		// },
		{
			label: t('性别'),
			prop: 'gender',
			minWidth: 120,
			dict: options.gender
		},
		{ label: t('属于门店'), prop: 'shop', minWidth: 140, dict: dict.get('Shop') },
		{
			label: t('科室'),
			prop: 'department',
			minWidth: 120,
			dict: options.department
		},
		{ label: t('职称'), prop: 'title', minWidth: 140, dict: options.title },
		{
			label: t('简介'),
			prop: 'introduction',
			showOverflowTooltip: true,
			minWidth: 200
		},
		// {
		// 	label: t('接诊时间'),
		// 	prop: 'receptionTime',
		// 	minWidth: 170,
		// 	sortable: 'custom',
		// 	component: { name: 'cl-date-text' }
		// },
		// {
		// 	label: t('挂号费'),
		// 	prop: 'registrationFee',
		// 	minWidth: 140,
		// 	sortable: 'custom'
		// },
		// {
		// 	label: t('创建时间'),
		// 	prop: 'createTime',
		// 	minWidth: 170,
		// 	sortable: 'desc',
		// 	component: { name: 'cl-date-text' }
		// },
		// {
		// 	label: t('更新时间'),
		// 	prop: 'updateTime',
		// 	minWidth: 170,
		// 	sortable: 'custom',
		// 	component: { name: 'cl-date-text' }
		// },
		{ type: 'op', buttons: ['edit', 'delete'] }
	]
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.doctor.info
	},
	app => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
